home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************\
- * *
- * main.c -- Fastgraph (tm) and Fastgraph/Light (tm) demo program v4.0 *
- * *
- * This program is provided without warranty of any kind. It may *
- * be distributed freely as long as the files are not modified. You *
- * may use this source code in your own applications as long as it *
- * clearly understood that we are not responsible for any bugs in *
- * this code or in your code. Use this code freely, use it in good *
- * health, but use it at your own risk. Further disclaimers are *
- * listed at the end of this file. *
- * *
- * This program requires Fastgraph 4.0 or Fastgraph/Light 4.0 to link. *
- * Please call Ted Gruber Software at (702) 735-1980 for information *
- * about Fastgraph. *
- * *
- \**********************************************************************/
-
- #include "defs.h"
-
- /**********************************************************************\
- * *
- * main *
- * *
- \**********************************************************************/
-
- void main()
- {
- int current;
-
- /* save the original video mode number */
-
- old_mode = fg_getmode();
-
- /* make sure the required video modes are available */
-
- if (fg_testmode(16,PAGES) == 0 || fg_testmode(20,4) == 0)
- abort_program("This program requires VGA graphics.\n");
-
- /* benchmark the system speed */
-
- clockspeed = fg_measure();
-
- /* spawn the TGSDEMO program as a 320x200x256 intro to FGDEMO */
-
- if (exists("TGSDEMO.EXE") && exists("TGSDEMO.FGI"))
- spawnlp(P_WAIT,"TGSDEMO.EXE",NULL);
-
- /* now switch to 640x350x16 graphics for the remainder of FGDEMO */
-
- initialize();
-
- /* read the 14pt bitmapped font */
-
- get_font();
-
- /* construct the main menu on the hidden page */
-
- current = 0;
- draw_screen(current);
-
- /* display the main FGDEMO menu */
-
- fg_mousevis(OFF);
- outward_tunnel_effect(clockspeed/8);
-
- /* and start the tour! */
-
- fg_mousevis(ON);
- redraw = TRUE;
- selection = 0;
- horizontal_menu(main_menu,ITEMS,current);
- terminate();
- }
-
- /**********************************************************************\
- * *
- * draw_screen -- draw the main menu screen on the hidden page *
- * *
- \**********************************************************************/
-
- void draw_screen(int current)
- {
- int y2, y3;
-
- y2 = 21; y3 = 38;
-
- fg_mousevis(OFF);
-
- menu_top = y2 + 1;
- menu_bottom = y3 + 1;
-
- /* erase the hidden page */
-
- background = 15;
- fg_setpage(hidden);
- fg_erase();
-
- /* draw some rectangles */
-
- fg_setcolor(15);
- fg_rect(0,xlimit,0,ylimit);
-
- fg_setcolor(0);
- fg_rect(0,xlimit,0,y2);
-
- /* draw the large dithered rectangles */
-
- fg_setcolor(9);
- fg_drect(0,xlimit,0,20,matrix1);
- fg_setcolor(11);
- fg_drect(0,xlimit,39,ylimit,matrix2);
-
- /* put the title in the title bar */
-
- fg_setcolor(15);
- center_pstring("Fastgraph Demo",0,xlimit,20);
-
- fg_setcolor(8);
- fg_box(0,xlimit,0,ylimit);
-
- /* draw some black and grey outlines */
-
- fg_setcolor(7);
- fg_boxdepth(2,2);
- fg_box(1,xlimit-1,1,ylimit-1);
- fg_boxdepth(1,1);
-
- fg_setcolor(0);
- fg_box(3,xlimit-3,3,38);
- fg_box(3,xlimit-3,3,ylimit-3);
- fg_box(4,xlimit-4,3,ylimit-3);
-
- /* draw those little boxes in the corners */
-
- fg_setcolor(7);
- fg_rect(5,25,4,20);
- fg_rect(xlimit-25,xlimit-5,4,20);
-
- /* display the horizontal menu */
-
- horizontal_menu(main_menu,-ITEMS,current);
- fg_setpage(visual);
- }
-
- /**********************************************************************\
- * *
- * draw_window -- display a pop-up window *
- * *
- \**********************************************************************/
-
- void draw_window(int xmin,int xmax,int ymin,int ymax,char *string)
- {
- register int y;
-
- /* display the window and its border */
-
- fg_setcolor(15);
- fg_rect(xmin,xmax,ymin,ymax);
- fg_setcolor(0);
- fg_boxdepth(1,2);
- fg_box(xmin,xmax,ymin,ymax);
- fg_boxdepth(1,1);
-
- /* display the header bar at the top of the window */
-
- y = ymin + PTSIZE + 1;
- fg_rect(xmin,xmax,ymin,y+1);
-
- /* dither the header bar */
-
- fg_setcolor(7);
- fg_rect(xmin+2,xmin+22,ymin+1,y);
- fg_rect(xmax-22,xmax-2,ymin+1,y);
- fg_setcolor(9);
- fg_drect(xmin+23,xmax-23,ymin+1,y,matrix1);
-
- /* display the text in the window's header bar */
-
- fg_setcolor(15);
- center_pstring(string,xmin,xmax,y+1);
-
- /* display the window's shadow */
-
- fg_setcolor(8);
-
- fg_rect(xmin+3,xmax+3,ymax+1,ymax+2);
- fg_rect(xmax+1,xmax+3,ymin+2,ymax);
- }
-
- /**********************************************************************\
- * *
- * erase_window -- erase the previously displayed pop-up window *
- * *
- \**********************************************************************/
-
- void erase_window(int xmin,int xmax,int ymin,int ymax)
- {
- register int x1, x2;
-
- /* restore the original area underneath the window */
-
- x1 = xmin & 0xFFF8;
- x2 = ((xmax+3) & 0xFFF8) + 7;
- fg_mousevis(OFF);
- fg_restore(x1,x2,ymin,ymax+2);
-
- /* redraw the dither pattern on the hidden page */
-
- fg_setpage(hidden);
- fg_setcolor(15);
- fg_rect(x1,x2,ymin,ymax+2);
- fg_setcolor(11);
- fg_drect(x1,x2,ymin,ymax+2,matrix2);
-
- fg_setpage(visual);
- }
-
- /**********************************************************************\
- * *
- * get_answer -- accept a YES or NO answer from the keyboard or mouse *
- * *
- \**********************************************************************/
-
- get_answer(int xmin,int xmax,int y)
- {
- int color;
- int count, lastx, lasty;
- int return_value;
- int x;
- int x1, x2, y1, y2;
- char yes_no[4];
- unsigned char key, aux;
-
- /* if using a mouse, display the "Yes" and "No" buttons */
-
- if (mouse)
- {
- color = fg_getcolor();
- x1 = ((3 * xmin) + xmax) / 4;
- x2 = ((3 * xmax) + xmin) / 4;
- y1 = y - PTSIZE/2 - 1;
- y2 = y + PTSIZE/2 + 1;
- fg_setcolor(0);
- fg_boxdepth(1,2);
- fg_box(x1-25,x1+25,y1,y2);
- fg_box(x2-25,x2+25,y1,y2);
- fg_boxdepth(1,1);
- center_pstring("Yes",x1,x1,y2);
- center_pstring("No",x2,x2,y2);
- fg_setcolor(8);
- fg_rect(x1-23,x1+27,y2+1,y2+2);
- fg_rect(x1+26,x1+27,y1+2,y2);
- fg_rect(x2-23,x2+27,y2+1,y2+2);
- fg_rect(x2+26,x2+27,y1+2,y2);
- fg_mousevis(ON);
- }
-
- /* read keystrokes until Y, y, N, n, or Esc is pressed */
-
- flushkey();
- for (;;)
- {
- fg_waitfor(2);
- fg_intkey(&key,&aux);
- key = (unsigned char)tolower(key);
-
- if (mouse)
- {
- fg_mousebut(1,&count,&lastx,&lasty);
- if (BETWEEN(lastx,x1-25,x1+25) && BETWEEN(lasty,y1,y2))
- key = 'y';
- else if (BETWEEN(lastx,x2-25,x2+25) && BETWEEN(lasty,y1,y2))
- key = 'n';
- }
-
- if (key == 'y')
- {
- x = x1;
- strcpy(yes_no,"Yes");
- return_value = TRUE;
- break;
- }
- else if (key == 'n' || key == ESC)
- {
- x = x2;
- strcpy(yes_no,"No");
- return_value = FALSE;
- break;
- }
- }
-
- /* if using the mouse, flash the selected button */
-
- if (mouse)
- {
- fg_mousevis(OFF);
- fg_setcolor(0);
- fg_rect(x-23,x+23,y1+1,y2-1);
- fg_setcolor(15);
- center_pstring(yes_no,x,x,y2);
- fg_waitfor(2);
- fg_setcolor(15);
- fg_rect(x-23,x+23,y1+1,y2-1);
- fg_setcolor(0);
- center_pstring(yes_no,x,x,y2);
- fg_waitfor(2);
- fg_setcolor(color);
- }
-
- return(return_value);
- }
-
- /**********************************************************************\
- * *
- * info_window -- display text information in a window *
- * *
- \**********************************************************************/
-
- void info_window(int xmin,int xmax,int ymin,char *string[],int nstrings)
- {
- register int i;
- int x, y;
- int miny, maxy;
- int len, maxlen;
-
- /* center text in window according to length of longest string */
-
- maxlen = 0;
- for (i = 1; i < nstrings; i++)
- {
- len = length_pstring(string[i]);
- if (len > maxlen) maxlen = len;
- }
-
- /* calculate top and bottom of info window */
-
- miny = ymin;
- maxy = miny + (nstrings+1) * (PTSIZE+1);
-
- /* draw the info window on the hidden page first */
-
- fg_setpage(hidden);
-
- /* draw the window and put the first string in the header bar */
-
- draw_window(xmin,xmax,miny,maxy,string[0]);
-
- /* calculate starting point for text */
-
- x = xmin + ((xmax - xmin) - maxlen) / 2;
- y = miny + ((PTSIZE+1)*2) + PTSIZE/2;
-
- /* put all the strings in the rest of the window */
-
- fg_setcolor(0);
- for (i = 1; i < nstrings; i++)
- {
- put_pstring(string[i],x,y);
- y += PTSIZE+1;
- }
-
- /* restore the window to the visual page */
-
- fg_setpage(visual);
- fg_restore(xmin,xmax+3,miny,maxy+2);
-
- /* redraw the dither pattern on the hidden page */
-
- fg_setpage(hidden);
- fg_setcolor(15);
- fg_rect(xmin,xmax+3,miny,maxy+2);
- fg_setcolor(11);
- fg_drect(xmin,xmax+3,miny,maxy+2,matrix2);
-
- fg_setpage(visual);
-
- }
-
- /**********************************************************************\
- * *
- * outward_tunnel_effect *
- * *
- * Starting at the screen center, reveal the hidden page contents *
- * through a series of concentric hollow rectangles. *
- * *
- \**********************************************************************/
-
- void outward_tunnel_effect(delay)
- int delay;
- {
- int xmin, xmax;
- int ymin, ymax;
-
- xmin = 312;
- xmax = 327;
- ymin = 170;
- ymax = 179;
-
- while (xmin >= 0)
- {
- fg_restore(xmin,xmax,ymin,ymin+5);
- fg_restore(xmax-7,xmax,ymin,ymax);
- fg_restore(xmin,xmax,ymax-4,ymax);
- fg_restore(xmin,xmin+7,ymin,ymax);
- fg_stall(delay);
-
- xmin -= 8;
- xmax += 8;
- ymin -= 5;
- ymax += 5;
- }
- }
-
- /**********************************************************************\
- * *
- * Further Disclaimers *
- * *
- * Under no circumstances shall Ted Gruber Software be liable for any *
- * loss of profit or any other commercial damage, including but not *
- * limited to special, incidental, consequential, or other damages *
- * resulting from the use of or the inability to use the software, *
- * even if Ted Gruber Software has been notified of the possiblity *
- * of such damages. Ted Gruber Software disclaims all other warranties, *
- * either expressed or implied, regarding the merchantability or *
- * fitness of this software and accompanying documentation for any *
- * particular application or purpose. *
- * *
- \**********************************************************************/